comment |
   This program displays the key codes that Int 15H, service 4FH, 
   Keyboard Intercept, receives from Int 9 on AT computers.  You 
   will have to reboot when you are finished using this program.
   Save as: Snoop15.ASM
   Compile: MASM SNOOP15;
   	    LINK SNOOP15;		(ignore no-stack warning)
	    EXE2BIN SNOOP15.EXE SNOOP15.COM
	|

cseg	segment
	assume cs:cseg, ds:cseg
		org	100h			;.COM file format
start:		jmp	short begin

vidseg		dw	0b800h			;Use 0B000h for MCA & Herc.
old15		equ	this dword
old15_off	dw	?
old15_seg	dw	?
hextbl		db	'0123456789ABCDEF'
posn		dw	0

new15:		pushf				;Save flags
		cmp	ah,4fh			;Keyboard intercept?
		je	@F			;Yes -- go
		popf				;Else pop flags
		jmp	CS:[old15]		;And let original handle it
  @@:		push	ax			;Save registers
  		push	bx
		push	cx
		push	di
		push	ds
		push	es
		push	cs
		pop	ds
		mov	es,[vidseg]		;ES ==> video segment
		mov	di,[posn]		;ES:DI ==> next character
  		cmp	di,160			;Past end of first row?
  		jb	@F			;No -- continue
		sub	di,di			;Else start back at beginning
  @@:		mov	bx,offset hextbl	;For translations
		mov	ah,al			;Copy scan code to AH
		mov	cl,4			;Bit positions to shift
		shr	al,cl			;AL has high nibble
		xlat	[bx]			;Get ASCII code
		stosb				;Store in video ram
		inc	di			;Point to next char. locn.
		mov	al,ah			;Get back original
		and	al,0fh			;Get low nibble in AL
		xlat	[bx]			;Get ASCII code
		stosb				;Put on screen
		add	di,3			;Move for next report
		mov	[posn],di		;  and save position
		pop	es	  		;Recover registers
		pop	ds
		pop	di
		pop	cx
		pop	bx
		pop	ax
		popf
		jmp	cs:[old15]		;Let old handler see code
end_tsr		equ	$

begin:		mov	ax,3515h		;Get Int 15H vector
		int	21h		
		mov	old15_off,bx		;  and save it
		mov	old15_seg,es
		mov	dx,offset new15		;Get our start address
		mov	ax,2515h		;Set as new Int 15H
		int	21h
		mov	dx,offset end_tsr	;DS:DX ==> end of our mem.
		int	27h			;Stay resident & end
cseg		ends
		end	start

